package com.work.sys.controller;

import com.work.common.utils.poi.ExcelUtil;
import com.work.sys.domain.SysUser;
import com.work.sys.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.work.common.annotation.Log;
import com.work.common.core.controller.BaseController;
import com.work.common.core.domain.AjaxResult;
import com.work.common.enums.BusinessType;

import java.util.List;

/**
 * 用户信息Controller
 *
 * @author lee
 * @date 2021-04-21
 */
@RestController
@RequestMapping("/sys/user")
@Api(tags = {"用户查询接口"}, value = "用户查询")
public class SysUserController extends BaseController {
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询用户信息列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "用户查询", notes = "查询所有注册用户")
    public AjaxResult list() {
        SysUser sysUser = new SysUser();
        sysUser.setDelFlag("0");
        List<SysUser> list = sysUserService.selectSysUserList(sysUser);
        return AjaxResult.success(list);
    }

    /**
     * 获取用户信息详细信息
     */
    @GetMapping(value = "/{userId}")
    public AjaxResult get(@PathVariable("userId") Long userId) {
        return AjaxResult.success(sysUserService.selectSysUserById(userId));
    }

    /**
     * 新增用户信息
     */
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUser sysUser) {
        return toAjax(sysUserService.insertSysUser(sysUser));
    }

    /**
     * 修改用户信息
     */
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUser sysUser) {
        return toAjax(sysUserService.updateSysUser(sysUser));
    }

    /**
     * 删除用户信息
     */
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds) {
        return toAjax(sysUserService.deleteSysUserByIds(userIds));
    }
}
